package com.atguigu.service.impl;

import com.atguigu.dao.BookDao;
import com.atguigu.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/12/20 20:07
 * @注释
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    @Override
    @Transactional
    public void buyBook(int userId, int bookId) {

        //查询图书的价格
        bookDao.findPriceByBookId(bookId);
        //更新图书的库存
        bookDao.updataStock(bookId);
        //更新用户的余额
        bookDao.updateBalance(userId, price);
    }
}
